/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pattern.runtimetest;


import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import com.pattern.model.Karyawan;
import com.pattern.services.CRUDService;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Rully Andhika
 */
public class RuntimeTest1 {
    
    public static void main(String[] args) {
        MysqlDataSource dataSource = new MysqlDataSource();
        dataSource.setUser("root");
        dataSource.setPassword("");
        dataSource.setDatabaseName("sample_data");
        dataSource.setServerName("localhost");
        dataSource.setPortNumber(3306);
        
        CRUDService service = new CRUDService();
        service.setDataSource(dataSource);
        
        Karyawan karyawan = new Karyawan();
        //Tes Insert data karyawan
        // karyawan.setNik(1234567);
        karyawan.setNama("Superman");
        karyawan.setJabatan("Software Developer");
        karyawan.setBagian("IT Division");
        service.save(karyawan);
        
        // Cetak data yang di-insert
        System.out.println("NIK : " + karyawan.getNik());
        System.out.println("Nama : " + karyawan.getNama());
        System.out.println("Jabatan : " + karyawan.getJabatan());
        System.out.println("Bagian : " + karyawan.getBagian());
        // Tutup koneksi database
        try {
            dataSource.getConnection().close();
        } catch (SQLException ex) {
            Logger.getLogger(RuntimeTest1.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
}
